
//
//  LocationViewController.m
//  GoldOperationClient
//
//  Created by yaxue wang on 16/8/28.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "LocationViewController.h"

#import <BaiduMapAPI_Search/BMKSearchComponent.h>
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import <BaiduMapAPI_Location/BMKLocationComponent.h>
@interface LocationViewController()<BMKMapViewDelegate>
{
//    BMKMapView* _mapView;
    BMKPointAnnotation* pointAnnotation;

}
@property (nonatomic, strong) BMKMapView* mapView;

@end

@implementation LocationViewController

-(void)viewWillAppear:(BOOL)animated {
    [self.mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
}

- (BMKMapView *)mapView{
    if (_mapView == nil) {
        _mapView =[[BMKMapView alloc]initWithFrame:CGRectMake(0, 64, WindowWidth, WindowHeight-64)];
        _mapView.zoomLevel=15;
        [self.view addSubview:_mapView];
    }
    return _mapView;
}

-(void)viewWillDisappear:(BOOL)animated {
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
}

- (void)dealloc {
    if (_mapView) {
        _mapView = nil;
    }
}
- (void)initView
{
    [super initView];
    self.navBar.hidden=NO;
    [self setTitle:[self.dataDic objectForKey:@"addressName"]];


}

- (void) viewDidAppear:(BOOL)animated {
    // 添加一个PointAnnotation
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor;
    coor.latitude = [[self.dataDic objectForKey:@"latitude"]doubleValue];
    coor.longitude = [[self.dataDic objectForKey:@"longitude"]doubleValue];
    annotation.coordinate = coor;
    [_mapView addAnnotation:annotation];
}
 //Override
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorRed;
        newAnnotationView.animatesDrop = NO;// 设置该标注点动画显示
        return newAnnotationView;
    }
    return nil;
}
/**
 *地图初始化完毕时会调用此接口
 *@param mapview 地图View
 */
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView
{
    _mapView.centerCoordinate = CLLocationCoordinate2DMake([[self.dataDic objectForKey:@"latitude"]doubleValue], [[self.dataDic objectForKey:@"longitude"]doubleValue]);
   
}
@end
